package com.example.idachuappone.index.action;

import android.content.Context;
import android.content.Intent;
import com.example.idachuappone.index.welcomentity.Hot;
import com.example.idachuappone.index.welcomentity.PersonExpands;
import com.example.idachuappone.index.welcomentity.Tags;
import com.example.idachuappone.index.welcomentity.Top;
import com.example.idachuappone.index.welcomentity.WelcomeUri;
import com.example.idachuappone.person.item.WebViewActivity;
import com.example.idachuappone.utils.MainToast;
import java.util.Map;

public class IndexTwoAction {
    public void activityGoUriorUrl(Context context, WelcomeUri uri, String url, String title, boolean isurl) {
        if (isurl) {
            Intent intent = new Intent(context, WebViewActivity.class);
            intent.putExtra("url", url);
            intent.putExtra("title", title);
            context.startActivity(intent);
            return;
        }
        startUriActivity(context, uri, title);
    }

    public void activityGoHot(Context context, Hot hot) {
        if (hot.isUrl()) {
            Intent intent = new Intent(context, WebViewActivity.class);
            intent.putExtra("url", hot.getUrl());
            intent.putExtra("title", hot.getTitle());
            context.startActivity(intent);
            return;
        }
        startUriActivity(context, hot.getUri(), hot.getTitle());
    }

    public void activityGoTags(Context context, Tags tags) {
        if (tags.isUrl()) {
            Intent intent = new Intent(context, WebViewActivity.class);
            intent.putExtra("url", tags.getUrl());
            intent.putExtra("title", tags.getTitle());
            context.startActivity(intent);
            return;
        }
        startUriActivity(context, tags.getUri(), tags.getTitle());
    }

    public void activityGoExpands(Context context, PersonExpands personExpands) {
        if (personExpands.isUrl()) {
            Intent intent = new Intent(context, WebViewActivity.class);
            intent.putExtra("url", personExpands.getUrl());
            intent.putExtra("title", personExpands.getTitle());
            context.startActivity(intent);
            return;
        }
        startUriActivity(context, personExpands.getUri(), personExpands.getTitle());
    }

    public void activityGoTop(Context context, Top top) {
        if (top.isUrl()) {
            Intent intent = new Intent(context, WebViewActivity.class);
            intent.putExtra("url", top.getUrl());
            intent.putExtra("title", top.getTitle());
            context.startActivity(intent);
            return;
        }
        startUriActivity(context, top.getUri(), top.getTitle());
    }

    private void startUriActivity(Context context, WelcomeUri uri, String title) {
        try {
            String action = uri.getUrl().replace("/", ".");
            Intent intent = new Intent();
            intent.setAction(action);
            Map<String, String> map = uri.getParams();
            if (map != null) {
                for (String str : map.keySet()) {
                    intent.putExtra(str, (String) map.get(str));
                }
            }
            intent.putExtra("title", title);
            context.startActivity(intent);
        } catch (Exception e) {
            MainToast.show(context, "\u672c\u7248\u672c\u4e0d\u652f\u6301\u8be5\u70b9\u51fb\uff0c\u8bf7\u60a8\u66f4\u65b0\u5e94\u7528\u3002", 0);
        }
    }
}
